package com.ruoyi.system.api.aspect;

import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.system.api.annotation.TestAnnotation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;

@Aspect
@Component
public class TestSystemAspect {
    /**
     * 定义AOP签名 (切入所有使用鉴权注解的方法)
     */
    public static final String POINTCUT_SIGN = "@annotation(com.ruoyi.system.api.annotation.TestAnnotation)";

    /**
     * 声明AOP签名
     */
    @Pointcut(POINTCUT_SIGN)
    public void pointcut()
    {

    }

    /**
     * 环绕切入
     *
     * @param joinPoint 切面对象
     * @return 底层方法执行后的返回值
     * @throws Throwable 底层方法抛出的异常
     */
    @Around("pointcut()")
    public Object TestAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Signature signature = joinPoint.getSignature();

        MethodSignature signature1= (MethodSignature) joinPoint.getSignature();;
        Method method = signature1.getMethod();
       //获取方法上的权限注解
        TestAnnotation annotation = method.getAnnotation(TestAnnotation.class);
        if(annotation!=null){

        }

        //获取用户权限
        /*String quanxian="xixixixixi";
        if (!annotation.value().equals(quanxian)){
            throw new Throwable("权限不对请去进行授权！");
        }*/
        return joinPoint.proceed();
    }
}
